/*
 *  Packet.cpp
 *  TubeTruck
 *
 *  Created by Aeturnum on 5/21/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#include "Packet.h"

using namespace TTP;
using namespace std;
 
Packet::Packet() : mVersionNumber(TubeTruckVersion), mIdHash(), mPacketType(0)
{}
Packet::Packet(byte type) : mVersionNumber(TubeTruckVersion), mIdHash(), mPacketType(type)
{}
Packet::Packet(id_hash idHash, byte type) : mVersionNumber(TubeTruckVersion), mIdHash(idHash), mPacketType(type)
{}

Packet::~Packet() {}

// idHash

byte Packet::getType() const {
   return mPacketType;
}
uint32_t Packet::getVersionNumber() const {
   return mVersionNumber;
}

void Packet::setSourceIdHash(id_hash) {
   throw msg_exception("Packet does not have source ID hash.");
}
id_hash Packet::getSourceIdHash() const {
   throw msg_exception("Packet does not have source ID hash.");
}
void Packet::setDestIdHash(id_hash) {
   throw msg_exception("Packet does not have dest ID hash.");
}
id_hash Packet::getDestIdHash() const {
   throw msg_exception("Packet does not have dest ID hash.");
}

void Packet::fromVec(std::vector<byte>::const_iterator &vit, 
   const std::vector<byte>::const_iterator &end) {
   
   unserialize<uint32_t>(vit, end, mVersionNumber);
   
   mPacketType = *vit++;
   
   unserialize<uint32_t>(vit, end, mIdHash);
}

void Packet::toVec(std::vector<byte> &vec) const {
   serialize<uint32_t>(vec, mVersionNumber);
   vec.push_back(mPacketType);
   serialize<uint32_t>(vec, mIdHash);
}
